package com.bw.dg.controller;

import com.bw.dg.common.POIUtil;


import com.bw.dg.common.Result;
import com.bw.dg.common.StatusCode;
import com.bw.dg.pojo.People;
import com.bw.dg.service.PeopleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

/**
 * @ClassName PeopleController
 * @Description TODO
 * @Author 赫含星
 * @Date 2020/4/20 17:24
 * @Version 1.0
 **/
@RestController
@CrossOrigin
@RequestMapping(value = "/people")
public class PeopleController {
    @Autowired
    private PeopleService peopleService;

    /**
     * 查询人员管理
     * @return
     */
    @RequestMapping("/findList")
    public List findAll(){
        List people =  peopleService.findAll();
       return  people;
    }


    @RequestMapping("/findByName")
    public List  findName(@RequestParam("name") String name){
        List list = peopleService.findName(name);
        return list;
    }
    /**
     * 获取实体
     * @param id
     * @return
     */
   @RequestMapping("/findPeopleByid")
    public People findPeopleByid(@RequestParam("id") String id){
       People p =   peopleService.findPeopleByid(id);
       return p;
   }
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public String update(@RequestBody People people){
        peopleService.update(people);
        return "修改成功";
    }

   @RequestMapping(value = "/addPeople",method = RequestMethod.POST)
   public String addPeople(@RequestBody People people){
       people.setId(UUID.randomUUID().toString());
       people.setDid(1);
      peopleService.addPeople(people);
      return "添加成功";
   }

   @RequestMapping("/delete")
    public String delete(@RequestParam("id") String id){
       String[] ids = id.split(",");
       for(String aa:ids){
           this.peopleService.delete(aa);
       }
       return  "删除成功";
   }

//    //导入
//    @RequestMapping("/toLead")
//    @ResponseBody
//    public Result toLead() throws Exception {
//
//        List<People> tbEmployees = POIUtil.importExcel();
//        for(int i=1;i < tbEmployees.size();i++){
//            peopleService.addPeople(tbEmployees.get(i));
//        }
//        return  new Result(true, StatusCode.OK, "导入成功", user);
//    }
//    //导出
//    @RequestMapping("/derive")
//    @ResponseBody
//    public Result derive() throws Exception {
//
//        List<People> employeeList = peopleService.findAll();
//        POIUtil.export(employeeList);
//        return new Result(true, StatusCode.OK, "导出成功", user);
//    }
}
